package model

type SubjectRequest struct {
	ID     uint   `json:"id"`                                   //
	Name   string `json:"name" v:"name@required|name#name不能为空"` // 分类名
	Status uint   `json:"status"`                               // 状态
}

type SubjectResponse struct {
	ID         uint   `json:"id"`         //
	Name       string `json:"name"`       // 分类名
	CreateTime string `json:"createTime"` // 创建时间
	UpdateTime string `json:"updateTime"` // 更新时间
	DeleteTime string `json:"deleteTime"` // 删除时间
	Status     uint   `json:"status"`     // 状态
}

type SubjectResponsePage struct {
	Page Page              `json:"page"`
	List []SubjectResponse `json:"datalist"`
}

func (subjectRequest SubjectRequest) Convert() Subject {
	return Subject{
		Id:     subjectRequest.ID,
		Name:   subjectRequest.Name,
		Status: subjectRequest.Status,
	}
}

func (*SubjectResponse) Convert(subject *Subject) *SubjectResponse {
	return &SubjectResponse{
		ID:         subject.Id,
		Name:       subject.Name,
		CreateTime: subject.CreateTime.String(),
		DeleteTime: subject.DeleteTime.String(),
		UpdateTime: subject.UpdateTime.String(),
		Status:     subject.Status,
	}

}

func (Subject) Convert(subjects []Subject) []SubjectResponse {
	var subjectResponses = make([]SubjectResponse, len(subjects))
	for i := range subjects {
		subjectResponses[i] = *subjectResponses[i].Convert(&subjects[i])
	}
	return subjectResponses
}

func (Subject) ConvertPage(subjects []Subject, page Page) SubjectResponsePage {
	var subjectResponses = make([]SubjectResponse, len(subjects))
	for i := range subjects {
		subjectResponses[i] = *subjectResponses[i].Convert(&subjects[i])
	}
	return SubjectResponsePage{
		Page: page,
		List: subjectResponses,
	}
}
